<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //递归  定义 1自己调用自己  2自顶向下解决
        //递归原则 目的 函数的作用 参数的作用 

        //    目的
        //   function fibonacci(i) {
        //      if(i ===0 || i===1) return 1
        //      return fibonacci(i-1) + fibonacci(i+2)
        //   }

        function maxSum(arr, i) {
            if (i === 0) return arr[0]
            if (i === 1) return Math.max(arr[0], arr[1])

            const a = maxSum(arr , i - 2) + arr[i]
            const b = maxSum(arr, i - 1)
            return Math.max(a,b)
        }


        const arr = [2, 33, 4, 1, 55, 3, 1, 2]
        console.log(maxSum(arr, arr.length - 1));
    </script>
</body>

</html>